g++ 3.2.X: undefined reference to `abs(int)'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Heiserer

    g++ 3.2.X: undefined reference to `abs(int)'

    hi,

    I am sure that is a stupid error of mine, but why the hell
    does this not work:
    -------------------------------------------[color=blue]
    >g++ test.cc[/color]
    /tmp/ccUN1Hel.o: In function `main':
    /tmp/ccUN1Hel.o(.tex t+0x26): undefined reference to `abs(int)'
    collect2: ld returned 1 exit status
    -------------------------------------------[color=blue]
    > cat test.cc[/color]
    #include <stdlib.h>
    #include <stdio.h>

    int main(){
    int abs(int);
    for (int jj=10;jj>=-10;jj--){
    fprintf(stdout, "%d ===> %d\n",jj,abs(jj ));
    }
    return 0;
    }
    -------------------------------------------[color=blue]
    >man 3 abs[/color]
    ABS(3) Linux Programmer's
    Manual ABS(3)
    NAME
    abs, labs, llabs, imaxabs - compute the absolute value of an
    integer.
    SYNOPSIS
    #include <stdlib.h>

    int abs(int j);
    long int labs(long int j);
    long long int llabs(long long int j);
    -------------------------------------------
    thanks, daniel
  • Attila Feher

    #2
    Re: g++ 3.2.X: undefined reference to `abs(int)'

    Daniel Heiserer wrote:[color=blue]
    > hi,
    >
    > I am sure that is a stupid error of mine, but why the hell
    > does this not work:
    > -------------------------------------------[color=green]
    >> g++ test.cc[/color]
    > /tmp/ccUN1Hel.o: In function `main':
    > /tmp/ccUN1Hel.o(.tex t+0x26): undefined reference to `abs(int)'
    > collect2: ld returned 1 exit status
    > -------------------------------------------[color=green]
    >> cat test.cc[/color]
    > #include <stdlib.h>
    > #include <stdio.h>
    >
    > int main(){
    > int abs(int);[/color]

    You don't need the above line. <stdlib.h> declares abs so you must not do
    it.

    --
    Attila aka WW


    Comment

    • Chris Dams

      #3
      Re: g++ 3.2.X: undefined reference to `abs(int)'

      Daniel Heiserer <Daniel.Heisere r@bmw.de> writes:

      Hello,
      [color=blue]
      >#include <stdlib.h>
      >#include <stdio.h>[/color]

      Should nowadays be:

      #include <cstdlib>
      #include <cstdio>

      using namespace std;
      [color=blue]
      >int main(){
      > int abs(int);[/color]

      Remove this line, that will solve the error.
      [color=blue]
      > for (int jj=10;jj>=-10;jj--){
      > fprintf(stdout, "%d ===> %d\n",jj,abs(jj ));
      > }
      > return 0;
      >}[/color]

      Bye,
      Chris Dams

      Comment

      Working...